<%@page import="db.DbConn"%>
<%@page import="java.awt.Window"%>
<%@page import="twitter4j.auth.RequestToken"%>
<%@page import="twitter4j.auth.AccessToken"%>
<%@page import="twitter4j.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	Twitter twit = (Twitter) session.getAttribute("twitter");
	RequestToken reqTok = (RequestToken) session
			.getAttribute("requestToken");
	System.out.println(reqTok.getToken());
	String oauth_tok = request.getParameter("oauth_token");
	String oauth_verifier = request.getParameter("oauth_verifier");
	AccessToken act = null;
	if (reqTok.getToken().equals(oauth_tok)) {
		try {
			act = twit.getOAuthAccessToken(reqTok, oauth_verifier);
		} catch (TwitterException e) {
			e.printStackTrace();
		}
		
		//accessToken save
		System.out.println(act.getToken());
		System.out.println(act.getTokenSecret());
		session.removeAttribute("twitter");
		session.removeAttribute("requestToken");
		
		String userid= (String)session.getAttribute("userId");
		DbConn conn = new DbConn();
		conn.setDbUrl(getServletContext().getInitParameter("dbUrl"));
		conn.setDbUser(getServletContext().getInitParameter("dbUser"));
		conn.setDbPass(getServletContext().getInitParameter("dbPass"));
		conn.setAccessToken(userid,act.getToken(),act.getTokenSecret());
				
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script type="text/javascript">
	window.location = "dailymission.jsp";
</script>
</html>